package com.example.zte.myapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zte.myapplication.R;

import java.util.List;
import java.util.Map;

/**
 * Created by ZTE on 2021/5/8.
 */

public class MyAdapter extends BaseAdapter {
    List<Map<String, Object>> list;
    private Context context;

    public MyAdapter(Context context, List<Map<String, Object>> list) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // 初始化布局
        View view = LayoutInflater.from(context).inflate(R.layout.list_item_language, null);

        TextView textView = (TextView)view.findViewById(R.id.name);
        ImageView imageView =(ImageView)view.findViewById(R.id.icon);

        Map<String, Object> map = list.get(position);
        textView.setText(map.get("xx1").toString());
        imageView.setImageResource((int)map.get("xx2"));
        return view;
    }
}
